<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.gouwudai.gobbs.vo.MasterLoginVO"%>
<%@ include file="../../common/common.jsp" %>		
<%
response.setHeader("Pragma","No-cache");//HTTP 1.1
response.setHeader("Cache-Control","no-cache");//HTTP 1.0
response.setHeader("Expires","0");//防止被proxy

boolean successFlag = false;
String redirectUrl = ParamUtils.getStringParameter(request,"redirectUrl");	//拥有权限后跳转的页面

String loginId, password, cookieSave;

if(request.getMethod().equals("POST")){
	loginId = request.getParameter("loginId").trim();
	password = request.getParameter("password").trim();
	cookieSave = request.getParameter("cookieSave");
	try
	{
		IMasterService masterService = (IMasterService)BeanManager.getBean("masterService");
		MasterLoginVO vo = masterService.masterLogin(loginId,password,request.getRemoteAddr());
		session.setAttribute("MASTER_LOGIN",vo);
		//如果之前以用户身份登陆过前台，则要清除
		if(session.getAttribute("USER_LOGIN")!=null)
			session.removeAttribute("USER_LOGIN");
		if(cookieSave.equals("1"))
		{
			Cookie c_loginId = new Cookie("M_LOGIN_ID",loginId);
			Cookie c_password = new Cookie("M_PASSWORD",password);
			c_loginId.setMaxAge(100*60*60*24);
			c_password.setMaxAge(100*60*60*24);
			response.addCookie(c_loginId); 
			response.addCookie(c_password); 
		}
		else
		{
			Cookie c_loginId = new Cookie("M_LOGIN_ID",null);
			Cookie c_password = new Cookie("M_PASSWORD",null);
			c_loginId.setMaxAge(0);
			c_password.setMaxAge(0);
			response.addCookie(c_loginId); 
			response.addCookie(c_password); 
		}	
		successFlag = true;
	}
	catch(NotLoginException e)
	{
		Utility.NotLoginException(request,response,e);		
	}
	if(successFlag)	
	{		
		if(!redirectUrl.equals(""))
			response.sendRedirect(redirectUrl);		
		else
			response.sendRedirect("index.jsp");	
	}
}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - 管理员登陆</title>
<%@ include file="../../common/meta.inc" %>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<body>
<br/>
<br/>
<br/>
<table width="300" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#e6e6e6">
  <tr>
    <td align="center"><strong><%=SYSTITLE%>社区后台登录系统</strong></td>
  </tr>
</table>
<form name="form1" method="post" action="master_login.jsp">
<input type="hidden" name="redirectUrl" value="<%=redirectUrl%>">
<table width="300" height="93" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#e6e6e6">
<%=HtmlConst.tableError(Utility.trimNull(request.getAttribute("ERROR_MSG")),2)%>
  <tr bgcolor="#f6f6f6">
    <td width="80" height="22" bgcolor="#f6f6f6"><strong>管理员ID</strong></td>
    <td><input name="loginId" type="text" id="loginId" size="20" maxlength="30"></td>
  </tr>
    <tr bgcolor="#f6f6f6">
      <td height="10" bgcolor="#f6f6f6"><strong>登录密码</strong></td>
      <td><input name="password" type="password" id="password" size="20" maxlength="30"></td>
    </tr>
    <tr bgcolor="#f6f6f6">
      <td height="11" bgcolor="#f6f6f6"><strong>记住密码</strong></td>
      <td>
		<input name="cookieSave" type="radio" value="0" checked>不记录
		&nbsp;&nbsp;
		<input type="radio" name="cookieSave" value="1">记录
	  </td>
    </tr>
    <tr bgcolor="#f6f6f6">
      <td height="22" bgcolor="#f6f6f6">&nbsp;</td>
      <td><input name="submit" type="submit" id="submit" value="登录"></td>
    </tr> 
</table>
</form>
</body>
</html>